package com.kyl.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.kyl.base.ResponseResult;
import com.kyl.dto.DeptDto;
import com.kyl.service.DeptService;
import com.kyl.vo.DeptVo;
import com.kyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @title DeptController
 * @description 部门的前端控制器
 * @author WanJl
 * @version 1.0
 * @create 2025/1/6
 */
@Slf4j
@Api(tags = "部门管理相关接口")
@RestController
@RequestMapping("/dept")
public class DeptController {
    @Resource
    private DeptService deptService;

    @PostMapping("list")
    @ApiOperation(value = "部门列表",notes = "部门列表")
    @ApiImplicitParam(name = "deptDto", value = "部门DTO对象", required = true, dataType = "DeptDto")
    public ResponseResult<List<DeptVo>> deptList(@RequestBody DeptDto deptDto){
        log.debug("deptDto参数",deptDto);
        //调用service进行查询
        List<DeptVo> list=deptService.findDeptList(deptDto);
        return ResponseResult.success(list);
    }

    @PutMapping
    @ApiOperation(value = "新增部门",notes = "新增部门")
    @ApiImplicitParam(name = "deptDto", value = "部门DTO对象", required = true, dataType = "DeptDto")
    public ResponseResult<Boolean> createDept(@RequestBody DeptDto deptDto){
        return ResponseResult.success(deptService.createDept(deptDto));
    }

    @PatchMapping
    @ApiOperation(value = "修改部门",notes = "修改部门")
    @ApiImplicitParam(name = "deptDto", value = "部门DTO对象", required = true, dataType = "DeptDto")
    public ResponseResult<Boolean> updateDept(@RequestBody DeptDto deptDto){
        return ResponseResult.success(deptService.updateDept(deptDto));
    }

    @DeleteMapping("/{deptId}")
    @ApiOperation(value = "删除部门",notes = "删除部门")
    @ApiImplicitParam(name = "deptId", value = "部门id", required = true, dataType = "String")
    public ResponseResult<Boolean> removeDept(@PathVariable String deptId){
        return ResponseResult.success(deptService.removeDept(deptId));
    }


    @PatchMapping("/is_enable")
    @ApiOperation(value = "启动-禁用部门",notes = "启动-禁用部门")
    @ApiImplicitParam(name = "deptDto", value = "部门DTO对象", required = true, dataType = "DeptDto")
    public ResponseResult<Boolean> isEnableDept(@RequestBody DeptDto deptDto){
        return ResponseResult.success(deptService.isEnableDept(deptDto));
    }

    @PostMapping("tree")
    @ApiOperation(value = "部门树形展示",notes = "部门树形展示")
    public ResponseResult<TreeVo> deptTreeVo(){
        TreeVo treeVo = deptService.deptTreeVo();
        return ResponseResult.success(treeVo);
    }
}
